// components/ShopCart/ShopCart.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goodsObj: {
      type: Object
    },
    isHandle:{
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  lifetimes: {
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 计算总价，传递参数
    computedPrice(obj){
      this.setData({
        goodsObj: obj
      })
      // console.log(this.data.goodsObj)
      let allPrice = this.properties.goodsObj.count * this.properties.goodsObj.goods_price;
      this.triggerEvent('countChange', {id: this.properties.goodsObj.goods_id, count: this.properties.goodsObj.count, totalPrice: allPrice});

    },
    // 加
    add(){
      let obj = this.properties.goodsObj;
      obj.count++;
      this.computedPrice(obj);
    },
    // 减
    mins(){
      if(this.properties.goodsObj.count){
        let obj = this.properties.goodsObj;
        obj.count--;
        this.computedPrice(obj);
      }
    }
  }
})
